using System;
using System.Drawing;
using System.Windows.Forms;


namespace VisualEditorUILib
{
    sealed class GControlFactory
    {
        #region Variables

        private static volatile GControlFactory instance;
        private static object syncObj = new Object();
        private static int counter = 0;

        #endregion

        #region Constructors

        //just private constructor
        private GControlFactory()
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// for getting instance of factory
        /// </summary>
        public static GControlFactory Instance
        {
            get
            {
                if ( null == instance )
                {
                    lock ( syncObj )
                    {
                        if (null == instance)
                        {
                            instance = new GControlFactory();
                        }
                    }
                }

                return instance;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// produces new standard control.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public Control GetControl ( string type)
        {
            if (typeof(ApplicationGenerator.Forms.WebControls.TextBoxControl).FullName == type)
            {
                TextBox tmp_textBox = new TextBox();
                tmp_textBox.Enabled = false;
                return tmp_textBox;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.LabelControl).FullName == type)
            {
                Label tmp_label = new Label();
                tmp_label.Text = "Label";
                tmp_label.Enabled = false;
                tmp_label.BackColor = Color.Transparent;
                return tmp_label;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.CheckBoxControl).FullName == type)
            {
                CheckBox tmp_chckbx = new CheckBox();
                tmp_chckbx.Enabled = false;
                return tmp_chckbx;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.ButtonControl).FullName == type)
            {
                Button tmp_button = new Button();
                tmp_button.Text = "Button"+counter;
                tmp_button.Enabled = false;
                counter++;
                return tmp_button;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.DisplayListControl).FullName == type)
            {
                ListBox tmp_listBox = new ListBox();
                tmp_listBox.Text = "ListBox";
                tmp_listBox.Enabled = false;
                return tmp_listBox;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.SetRelationControl).FullName == type)
            {
                LinkLabel tmp_linkLabel = new LinkLabel();
                //tmp_linkLabel.ForeColor = Color.Blue;
                //tmp_linkLabel.Font.Style = FontStyle.Underline;
                tmp_linkLabel.LinkBehavior = LinkBehavior.AlwaysUnderline;
                tmp_linkLabel.LinkColor = Color.Red;
                tmp_linkLabel.BorderStyle = BorderStyle.Fixed3D;
                tmp_linkLabel.LinkArea = new LinkArea(0, 9);
                
                tmp_linkLabel.Text = "Relation";
                tmp_linkLabel.Enabled = false;
                return tmp_linkLabel;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.SetListControl).FullName == type)
            {
                ListView tmp_listView = new ListView();
                tmp_listView.Text = "ListView";
                tmp_listView.Enabled = false;
                return tmp_listView;
            }
            else if (typeof(ApplicationGenerator.Forms.WebControls.DropDownListControl).FullName == type)
            {
                ComboBox tmp_comboBox = new ComboBox();
                tmp_comboBox.Text = "ComboBox";
                tmp_comboBox.Enabled = false;
                return tmp_comboBox;
            }

            throw new NotSupportedException(string.Format("Niedozwolony typ kontrolki: {0}", type));
        }

        /// <summary>
        /// produces new standard control.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public Control GetControlFromDesignerTypeName(string type)
        {
            return GetControl(type);
            //if ("TextBoxControl" == type)
            //{
            //    TextBox tmp_textBox = new TextBox();
            //    tmp_textBox.Enabled = false;

            //    return tmp_textBox;
            //}
            //else if ("LabelControl" == type)
            //{
            //    Label tmp_label = new Label();
            //    tmp_label.Text = "Label";
            //    tmp_label.Enabled = false;
            //    tmp_label.BackColor = Color.Transparent;
            //    return tmp_label;
            //}
            ///*else if ("RadioButtonControl" == type)
            //{
            //    RadioButton tmp_radioButton = new RadioButton();
            //    tmp_radioButton.Enabled = false;
            //    return tmp_radioButton;
            //}*/
            //else if ("CheckBoxControl" == type)
            //{
            //    CheckBox tmp_chckbx = new CheckBox();
            //    tmp_chckbx.Enabled = false;
            //    return tmp_chckbx;
            //}
            //return null;
        }

        #endregion

    }
}
